#ifndef __SRC_ELF_H__
#define __SRC_ELF_H__

#include "types.h"

/* 架构判断 */
#define EM_RISCV    243

#define EI_CLASS     4
#define ELFCLASSNONE 0
#define ELFCLASS32   1
#define ELFCLASS64   2
#define ELFCLASSNUM  3

#define ELFMAG "\177ELF"
#define EI_NIDENT 16

/* program header 类型*/
#define PT_LOAD 1

#define PF_X 0x1
#define PF_W 0x2
#define PF_R 0x4

/* ELF Header */
typedef struct {
    u8 e_ident[EI_NIDENT];
    u16 e_type;
    u16 e_machine;
    u32 e_version;
    u64 e_entry;
    u64 e_phoff;
    u64 e_shoff;
    u32 e_flags;
    u16 e_ehsize;
    u16 e_phentsize;
    u16 e_phnum;
    u16 e_shentsize;
    u16 e_shnum;
    u16 e_shstrndx;
} elf64_ehdr_t;

/* Program Header */
typedef struct {
    u32   p_type;
    u32   p_flags;
    u64   p_offset;
    u64   p_vaddr;
    u64   p_paddr;
    u64   p_filesz;
    u64   p_memsz;
    u64   p_align;
} elf64_phdr_t;

#endif